<template>
  <el-tree :props="props" :load="loadNode" lazy @node-click="clickHandle">
  </el-tree>
</template>


<script>
export default {
  data() {
    return {
      props: {label: 'name',children: 'zones',isLeaf: 'leaf'},
    };
  },
  methods: {
    clickHandle(data,node){
        // console.log("data---",data,'node---',node);
        this.$emit('sendTreeData',data)
    },
    loadNode(node, resolve) {
        console.log('node---',node);
      if (node.level === 0) {
        this.$api.selectItemCategoryByParentId()
        .then(res=>{
            if(res.data.status===200){
                console.log(res.data);
                return resolve(res.data.result)
            }
        })
      }
      if (node.level >= 1) {
        this.$api.selectItemCategoryByParentId({type:node.data.cid})
        .then(res=>{
            if(res.data.status===200){
                return resolve(res.data.result)
            }else{
                return resolve([])
            }
        })
      }

    },
  }
};
</script>